<?php
require_once 'DB.class.php';
class Marker
{
    private $latitude;
    private $longitude;
    private $name;
    private $address;

    public static function getMarkers($city)
    {
        $db = DB::getInstance();
        $stmt = $db->prepare("
            select name, address, longitude, latitude
            from hairdressing
            where state=:city
            and longitude is not null
            and latitude is not null
        ");
        if (!$stmt instanceof PDOStatement) {
            throw new Excepton("Cannot prepare the query");
        }
        if (!$stmt->execute(array('city' => $city))) {
            throw new Exception("Cannot execute the query: " . print_r($stmt->errorInfo(), true));
        }
        $markers = array();
        while ($row = $stmt->fetch())
        {
            $marker = new Marker();
            $marker->setLongitude($row['longitude']);
            $marker->setLatitude($row['latitude']);
            $marker->setName($row['name']);
            $marker->setAddress($row['address']);
            $markers[] = $marker;
        }
        return $markers;
    }

    public function getLatitude()
    {
        return $this->latitude;
    }

    public function getLongitude()
    {
        return $this->longitude;
    }

    public function getName()
    {
        return $this->name;
    }

    public function getAddress()
    {
        return $this->address;
    }

    public function setLatitude($latitude)
    {
        $this->latitude = $latitude;
    }

    public function setLongitude($longitude)
    {
        $this->longitude = $longitude;
    }

    public function setName($name)
    {
        $this->name = $name;
    }

    public function setAddress($address)
    {
        $this->address = $address;
    }

}
